<template>
  <div class="index-attendance sub-margin">
    <!-- <div class="sub-page-title">加分项</div> -->
    <div class="content">
      <div class="search-box">
        <el-menu
          size="small"
          :default-active="activeCode"
          class="search-menu-box"
          mode="horizontal"
          @select="onMenuClick">
          <el-menu-item v-for="item in menuInfo" :key="item.status" :index="item.status">
            {{ item.label }}
          </el-menu-item>
        </el-menu>
      </div>
      <div class="table-con">
        <div class="right-con">
          <AttendanceApprove v-if="activeCode === '1'" />
          <StaticsGather :showAll="showAll" :showType="activeCode" v-if="activeCode === '2' || activeCode === '5'" />
          <AttendanceForm v-if="activeCode === '3'" />
          <StaticsManNew :showAll="showAll" v-if="activeCode === '4'" />
          <AttendanceAbsenteeism v-if="activeCode === '6'"></AttendanceAbsenteeism>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import AttendanceApprove from './AttendanceApprove' // 审批
import StaticsGather from './StaticsGather' // 统计汇总
import StaticsManNew from './StaticsManNew'
import AttendanceForm from './AttendanceForm' // 注册
import AttendanceAbsenteeism from './AttendanceAbsenteeism'
export default {
  name: 'indexAttendance',
  components: {
    AttendanceApprove,
    StaticsGather,
    StaticsManNew,
    AttendanceForm,
    AttendanceAbsenteeism,
  },
  props: {
    chooseTab: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      menuInfo: [],
      menuList: [
        {
          label: '考勤审批',
          status: '1',
        },
        {
          label: '部门统计',
          status: '2',
        },
        {
          label: '考勤表单',
          status: '3',
        },
        {
          label: '我的统计',
          status: '4',
        },
        {
          label: '统计汇总',
          status: '5',
        },
        {
          label: '旷工记录',
          status: '6',
        },
      ],
      activeCode: '1',
      showAll: '1', // 统计角色（1个人统计，2个人部门，3全局）
    }
  },
  watch: {},
  computed: {
    ...mapGetters('role', ['isOtherRole', 'isNormalRole', 'isAdminRole', 'isMainRole', 'isOrgRole', 'isPartRole']),
  },
  created() {
    this.dealAudit()
  },
  mounted() {},
  methods: {
    onMenuClick(code) {
      this.activeCode = code
    },
    dealAudit() {
      const tabsData = []
      if (this.isAdminRole) {
        tabsData.push(
          this.menuList[4]
          // this.menuList[5]
        )
      }
      if (this.isMainRole || this.isPartRole) {
        tabsData.push(
          this.menuList[0],
          this.menuList[1]
          // this.menuList[5]
        )
      }
      if (this.isOrgRole) {
        tabsData.push(
          this.menuList[0],
          this.menuList[1],
          this.menuList[2],
          this.menuList[3]
          // this.menuList[5]
        )
      }
      if (this.isNormalRole) {
        tabsData.push(this.menuList[2], this.menuList[3])
      }
      if (this.isOtherRole) {
        tabsData.push(this.menuList[2], this.menuList[3])
      }
      this.menuInfo = Array.from(new Set(tabsData.map(JSON.stringify))).map(JSON.parse)

      // 数组排序
      this.menuInfo.sort((a, b) => {
        return a.status - b.status
      })
      this.activeCode = this.menuInfo[0].status
      if (this.chooseTab) {
        this.activeCode = this.chooseTab
      }
    },
  },
}
</script>
<style lang="scss" scoped>
@import '@styles/layout.scss';
.index-attendance {
  height: 100%;
  .content {
    // height: calc(100% - 78px);
    height: calc(100% - 8px);
    padding-bottom: 20px;
    display: flex;
    flex-direction: column;
    position: relative;
    .search-box {
      width: 100%;
      .el-menu {
        .is-active {
          font-weight: bold;
          font-size: 16px;
        }
      }
    }
    .table-con {
      flex: 1;
      display: flex;
      align-items: stretch;
      // padding: 20px 0;
      height: calc(100% - 50px);
      .left-con {
        width: 300px;
        height: 100%;
        overflow: auto;
        position: relative;
        border-right: 1px solid #e4eaf0;
      }

      .right-con {
        flex: 1;
        width: 100%;
        // max-width: 1200px;
        margin: 0 auto;
        // margin-left: 20px;
        position: relative;
        display: flex;
        flex-direction: column;
      }
    }
  }
}
</style>
